import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class lianxi5 {
    public static void main(String[] args) {
        File file = new File("C:\\2");
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.getName().contains(".jpeg")) {
                System.out.println(file1.getName());
                try (FileInputStream fis = new FileInputStream(file1.getAbsoluteFile());

                     FileOutputStream fot = new FileOutputStream("C:\\3\\" + file1.getName());)
                {

                    byte[] bytes = new byte[1024];
                    int read = 0;
                    while ((read = fis.read(bytes)) != -1) {
                        fot.write(bytes, 0, read);
                    } }catch (Exception e){
                    e.printStackTrace();



                }
            }
        }
    }
}
